package dk.mirasola.systemtraining.bridgewidgets.shared.factory;


import dk.mirasola.systemtraining.bridgewidgets.shared.model.Suit;

public class SuitFactory {
    public static String suitToString(Suit suit) {
        if (suit == null) {
            throw new NullPointerException();
        }

        switch (suit) {
            case CLUB:
                return "C";
            case DIAMOND:
                return "D";
            case HEART:
                return "H";
            case SPADE:
                return "S";
            default:
                throw new RuntimeException("Unknown suit: " + suit);
        }
    }

    public static Suit stringToSuit(String encodedStr) {
        if (encodedStr == null) {
            throw new NullPointerException();
        } else if (encodedStr.length() == 1) {
            return charToSeat(encodedStr.charAt(0));
        } else {
            throw new RuntimeException("Cannot parse '" + encodedStr + "' to suit");
        }
    }

    public static Suit charToSeat(char c) {
        switch (c) {
            case 'C':
                return Suit.CLUB;
            case 'D':
                return Suit.DIAMOND;
            case 'H':
                return Suit.HEART;
            case 'S':
                return Suit.SPADE;
            default:
                throw new RuntimeException("Cannot parse '" + c + "' to suit");
        }
    }

    private SuitFactory() {
    }
}
